home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-08 | 5.7 KB | 128 lines | [TEXT/ttxt] |
- 'PROGRAMMER'S NOTES (PICTure Animation)
- 'TANK-OFF II Copyright © 1995 Scotty Mooneyham. All rights reserved.
-
- 'This game was written in FUTURE BASIC v1.02™ for the Macintosh™.
- 'All art was drawn in ClarisWorks™.
- 'This file is for those that may be interested in the animation displayed
- 'by this game. I use 2 different routines, #1 for drawing the scenes and #2 for
- 'animating PICT resources.
-
- 'Before we start, here are a few routines that are needed to initilialize the routines
- 'that actually draw and animate PICT resources:
-
- DIM foreground&,background&,savebuffer&,Gdevice&
- DIM r.8 'global rectangle
- CALL GETGWORLD(foreground&,Gdevice&) 'get window's port
- CALL SETRECT(r,0,0,640,480)
- background& = FN getOffScrnGWorld&(@r) 'get memory for background buffer
- savebuffer& = FN getOffScrnGWorld&(@r) 'get memory for animateSavePict routine
-
- WINDOW OFF 'turn off the Command window
- WINDOW #1, "untitled", (0,0)-(640,480), _dialogPlain
-
- LOCAL MODE
- LOCAL FN setThePort (thePort&) 'direct graphics drawing to a specific port
- gDev& = FN GETGWORLDDEVICE(thePort&)
- CALL SETGWORLD(thePort&,0)
- END FN
-
- 'The 1st routine draws PICT resources onto an off-screen buffer and displays
- 'the whole thing with COPYBITS:
-
- ' Draw desert scene, sun, player's tank, tank's turrent and treads/flowers...
- FN drawPict(143,30,0) ' draw background scene
- FN drawPict(176,80,30) ' draw sun
- FN drawPict(133,x0%-31,y0%) ' draw player's tank
- FN drawPict(134,78,270) ' draw tread/flower #1
- FN drawPict(155,x%-15,y%-118) ' draw tank's turrent
- FN copyBits (background&,foreground&,@r,@r)
-
- 'The varibles x0%,y0%,x% and y% were used during development for
- 'animation alignment and are not relative here...
- 'Here are the routines that are called:
-
- LOCAL
- DIM rect.8
- LOCAL FN drawPict (pictID,xx,yy)
- myPICT& = FN GETPICTURE(pictID) 'get handle to PICT resource
- LONG IF myPICT& 'handle available?
- FN setThePort(background&) 'point to off-screen buffer
- PICTURE (xx,yy), myPICT& 'draw PICT
- FN setThePort(foreground&) 'point to visible screen
- END IF
- END FN
-
- 'and
-
- LOCAL MODE 'copy bitmap from offscreen to window
- DIM s.8
- DIM r.8
- LOCAL FN copyBits (offPort&,wndPort&,s;8,r;8)
- locked = FN LOCKPIXELS(FN GETGWORLDPIXMAP(offPort&))
- LONG IF locked
- CALL COPYBITS(#offPort&+2,#wndPort&+2,s,r,_srcCopy,0)
- CALL UNLOCKPIXELS(FN GETGWORLDPIXMAP(offPort&))
- END IF
- END FN
-
- 'The #1 method isn't used for the actual animation because it would be
- 'extremely slow (copying 640x480 = 307,200 pixels, using 256 colors).
- 'This routine is used to draw the background art while routine #2 (shown below)
- 'is used to animate a particular section of the screen:
-
- LOCAL
- DIM rect.8
- LOCAL FN animateSavePict (pictID,xx,yy,count,visLast)
- myPICT& = FN GETPICTURE(pictID)
- rect;8 = [myPICT&]+_picFrame
- CALL OFFSETRECT(rect,xx,yy)
- FN setThePort(savebuffer&)
- FN copyBits (background&,savebuffer&,@rect,@rect)
- FOR i=pictID TO pictID+count
- myPICT& = FN GETPICTURE(i)
- FN setThePort(background&)
- FN copyBits (savebuffer&,background&,@rect,@rect)
- FN setThePort(background&)
- PICTURE (xx,yy), myPICT&
- FN setThePort(foreground&)
- FN copyBits (background&,foreground&,@rect,@rect)
- NEXT i
- IF visLast>0 THEN FN copyBits (savebuffer&,foreground&,@rect,@rect)
- END FN
-
- 'Now an explanation is in order, this is what "animateSavePict" does...
- '1.This routine expects a series of PICT resources, beginning at "pictID" with
- ' the number of PICTs to be animated in "count" (whereas count=0 would mean
- ' only 1 picture would be available)
- '2.Get rectangle of first PICT and COPYBITS that rectangle from "background&" to
- ' "savebuffer&". Draw PICT onto "background&" and then COPYBITS same
- ' rectangle from "background&" to "foreground&". This in-direct drawing and copying
- ' is needed because the PICTs that are being drawn are object-based. Needing
- ' less memory (allowing more PICTs) but requiring more drawing time, which if
- ' drawn directly to "foreground&" would allow user to view PICT being drawn
- ' polygon-by-polygon, which would ruin the animation effect.
- ' "savebuffer&" is being used to store the pre-drawn playfield so when we draw
- ' an animation PICT over that area we can restore it fast and easy for the next
- ' frame (PICT) of animation.
- '3."xx" and "yy" are the horizontal and vertical positions where the animation PICTs
- ' will be drawn.
- '4."visLast" is used to tell the routine whether or not it should restore the screen
- ' back to it's original state before "animateSavePict" was called.
- ' For example:
- ' ***When the enemy tank fires, it restores the screen to it's previous state...
- 'FN animateSavePict (pictID,xx,yy,count,visLast***)
- FN animateSavePict (187,161,105,6,1***)
- ' ***But the "miss" routine doesn't: (when the sand flys up and leaves a hole)
- FN animateSavePict (194,31,110,4,0***)
-
- 'Better methods are available for animation, but these are the ones I used in
- 'TANK-OFF II. The hard part is having something to animate. I spent more time
- 'drawing in ClarisWorks™ (DRAWING MODE) than I did in FutureBasic™ programming.
-
- 'I hope this has helped somebody and that you enjoy the game. If any of this has
- 'helped/entertained you please send $5 (with comments/questions) to:
- 'Scotty Mooneyham
- '3345 Old Kentucky Road West
- 'Mosheim, TN. 37818
-
-